package exercise;

import java.util.PriorityQueue;

class SmallestInfiniteSet {

    private final PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();

    public SmallestInfiniteSet() {
        for (int i = 1; i <= 1000; i++) {
            priorityQueue.offer(i);
        }
    }

    public int popSmallest() {
        if (priorityQueue.isEmpty()) {
            return 1;
        } else {
            return priorityQueue.poll();
        }
    }

    public void addBack(int num) {
        if (priorityQueue.isEmpty()) {
            priorityQueue.offer(1);
            return;
        }

        if (priorityQueue.contains(num)) {
            return;
        }
        priorityQueue.add(num);
    }
}

public class LCode2336 {
    public static void main(String[] args) {
        SmallestInfiniteSet smallestInfiniteSet = new SmallestInfiniteSet();
        smallestInfiniteSet.addBack(2);
        System.out.println(smallestInfiniteSet.popSmallest());
        System.out.println(smallestInfiniteSet.popSmallest());
        System.out.println(smallestInfiniteSet.popSmallest());
        smallestInfiniteSet.addBack(1);
        System.out.println(smallestInfiniteSet.popSmallest());
        System.out.println(smallestInfiniteSet.popSmallest());
        System.out.println(smallestInfiniteSet.popSmallest());
    }
}
